package com.kaishengit.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.entity.Document;
import com.kaishengit.entity.Employee;
import com.kaishengit.entity.Project;
import com.kaishengit.service.DocumentService;
import com.kaishengit.service.EmployeeService;
import com.kaishengit.util.StringUtil;
import com.kaishengit.util.db.Page;
import com.kaishengit.util.web.ServletUtil;

public class DocumentList extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		
		HttpSession session = request.getSession();
		Project project = (Project) session.getAttribute("project");
		
		String p = request.getParameter("p");
		
		int pageNum = 1;
		if(StringUtil.isNotEmpty(p)) {
			try {
				pageNum = Integer.parseInt(p);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
		}
		
		Page<Document> page = new DocumentService().findByPage(pageNum,project.getId());
		request.setAttribute("page", page);
		
		ServletUtil.forward(request, response, "document");
	}


}
